package com.itboye.jigongbao.utils;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.signature.StringSignature;
import com.itboye.jigongbao.R;
import com.yancy.gallerypick.inter.ImageLoader;
import com.yancy.gallerypick.widget.GalleryImageView;


/**
 * 图片加载类
 */
public class XGlideLoader implements ImageLoader {
    /**
     * 单图片查看--加载图片
     *
     * @param context
     * @param path
     * @param imageView
     */
    public static void displayImage(Context context, String path, ImageView imageView) {

        String imgPath = path.startsWith("http") ? path : Const.Companion.getIMAGE_URL() + path;
        Glide.with(context).load(imgPath).error(R.drawable.shouye).placeholder(R.drawable.shouye).into(imageView);
        Log.v("request_params", "图片路径" + imgPath);
    }

    /**
     * 单图片查看--加载图片
     *
     * @param context
     * @param path
     * @param imageView
     */
    public static void displayImageForUser(Context context, String path, ImageView imageView) {
        String imgPath = path.startsWith("http") ? path : Const.Companion.getIMAGE_URL() + path;
        Glide.with(context).load(imgPath).error(R.drawable.shouye).placeholder(R.drawable.shouye).into(imageView);
        Log.v("request_params", "图片路径" + imgPath);
    }

    /**
     * 单图片查看--加载图片(圆形图片)
     *
     * @param context
     * @param path
     * @param imageView
     */
    public static void displayImageCircular(Context context, String path, ImageView imageView) {
        String imgPath = path.startsWith("http") ? path : Const.Companion.getIMAGE_URL() + path;
        Glide.with(context)
                .load(imgPath).signature(new StringSignature(String.valueOf(System.currentTimeMillis())))
                .transform(new GlideCircleTransform(context))
                .error(R.drawable.shouye).placeholder(R.drawable.shouye)
                .into(imageView);
        Log.v("request_params", "图片路径" + imgPath);

    }

    /**
     * 单图片查看--加载图片(圆形图片)
     *
     * @param context
     * @param path
     * @param imageView
     */
    public static void displayImageCircular(Context context, String path, ImageView imageView, boolean isChange) {
        String imgPath = path.startsWith("http") ? path : Const.Companion.getIMAGE_URL() + path;
        Glide.with(context)
                .load(imgPath)
                .transform(new GlideCircleTransform(context))
                .error(R.drawable.shouye).placeholder(R.drawable.shouye)
                .into(imageView);
        Log.v("request_params", "图片路径" + imgPath);

    }

    /**
     * 单图片查看--加载图片(圆形图片)
     *
     * @param context
     * @param path
     * @param imageView
     */
    public static void displayImageCircularForUser(Context context, String path, ImageView imageView) {
        String imgPath = path.startsWith("http") ? path : Const.Companion.getIMAGE_URL() + path;
        Glide.with(context)
                .load(imgPath)
                .skipMemoryCache(true) // 不使用内存缓存
                .diskCacheStrategy(DiskCacheStrategy.NONE) // 不使用磁盘缓存
                .signature(new StringSignature("01"))//增加签名
                .transform(new GlideCircleTransform(context))
                .error(R.drawable.head).placeholder(R.drawable.head)
                .into(imageView);
        Log.v("request_params", "图片路径" + imgPath);

    }

    public static void displayResourceImage(Context context, int resource, ImageView imageView) {
        Glide.with(context).load(resource).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).error(R.drawable.shouye).placeholder(R.drawable.shouye).into(imageView);
//        Log.v("request_params", "图片路径"+imgPath);
    }

    @Override
    public void displayImage(Activity activity, Context context, String path, GalleryImageView galleryImageView, int width, int height) {
        Glide.with(context)
                .load(path)
                .placeholder(R.mipmap.gallery_pick_photo)
                .centerCrop()
                .into(galleryImageView);
    }

    @Override
    public void clearMemoryCache() {

    }
}
